package com.qf.utils;

import com.qf.pojo.vo.Address;
import com.qf.pojo.vo.Business;
import com.qf.pojo.vo.BusinessAndType;
import com.qf.pojo.vo.PointVo;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class ListCaculate {
    static DecimalFormat df = new DecimalFormat("#0.00");
    public static List<BusinessAndType> distanceBT(List<BusinessAndType> list, Address address){
        List<BusinessAndType> blist3 = new ArrayList<>();
        for (BusinessAndType business:list) {
            PointVo a = new PointVo();
            PointVo b = new PointVo();
            a.setX1(business.getX1());
            a.setY1(business.getY1());
            b.setX1(address.getX1());
            b.setY1(address.getY1());
            double v = CaculateDistance.CaculateDistance(a,b)/1000.0;
            System.out.println("v = " + v);
            if(v<=20){
                business.setDistance(Double.valueOf(df.format(v)));
                blist3.add(business);
            }
        }
        return blist3;
    }
    public static List<Business> distanceB(List<Business> list, Address address){
        List<Business> blist3 = new ArrayList<>();
        for (Business business:list) {
            PointVo a = new PointVo();
            PointVo b = new PointVo();
            a.setX1(business.getX1());
            a.setY1(business.getY1());
            b.setX1(address.getX1());
            b.setY1(address.getY1());
            double v = CaculateDistance.CaculateDistance(a,b)/1000;
            System.out.println("v = " + v);
            if(v<=20){
                business.setDistance(Double.valueOf(df.format(v)));
                blist3.add(business);
            }
        }
        return blist3;
    }

}
